/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.neusoft.tyut.myspring.myproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/** 八股文代码 */
public class ProxyFactory {
    //    目标对象
    private SellTickets station;

    public void setStation(SellTickets station) {
        this.station = station;
    }

    public SellTickets getProxyObject() {
        SellTickets sellTickets =
                (SellTickets)
                        Proxy.newProxyInstance(
                                station.getClass().getClassLoader(),
                                station.getClass().getInterfaces(),
                                new InvocationHandler() {
                                    @Override
                                    public Object invoke(Object proxy, Method method, Object[] args)
                                            throws Throwable {
                                        System.out.println("代理点收取一些服务费用(JDK动态代理方式)");
                                        Object result = method.invoke(station, args);
                                        return result;
                                    }
                                });

        return sellTickets;
    }
}
